package com.khd.problems_0101_0200;

/**
 * 101. 对称二叉树
 * https://leetcode-cn.com/problems/symmetric-tree/
 *
 * @author kehandi
 * @title: Problem_0101_SymmetricTree
 * @projectName algorithm
 * @date 2022/3/28 23:19
 */
public class Problem_0101_SymmetricTree {

    public boolean isSymmetric(TreeNode root) {
        return check(root, root);
    }

    public boolean check(TreeNode p, TreeNode q) {
        if (p == null && q == null) {
            return true;
        }
        if (p == null || q == null) {
            return false;
        }
        return p.val == q.val && check(p.left, q.right) && check(p.right, q.left);
    }

    /**
     * 节点
     */
    static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;
    }

}
